package com.ruoyi.web.controller.obtain;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.obtain.dto.TransferDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.obtain.domain.TTransfer;
import com.ruoyi.obtain.service.ITTransferService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 移交他人Controller
 * 
 * @author ruoyi
 * @date 2022-11-12
 */
@RestController
@RequestMapping("/obtain/transfer")
public class TTransferController extends BaseController
{
    @Autowired
    private ITTransferService tTransferService;

    /**
     * 查询移交他人列表
     */
    @PreAuthorize("@ss.hasPermi('obtain:transfer:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTransfer tTransfer)
    {
        startPage();
        List<TTransfer> list = tTransferService.selectTTransferList(tTransfer);
        return getDataTable(list);
    }

    /**
     * 导出移交他人列表
     */
    @PreAuthorize("@ss.hasPermi('obtain:transfer:export')")
    @Log(title = "移交他人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTransfer tTransfer)
    {
        List<TTransfer> list = tTransferService.selectTTransferList(tTransfer);
        ExcelUtil<TTransfer> util = new ExcelUtil<TTransfer>(TTransfer.class);
        util.exportExcel(response, list, "移交他人数据");
    }

    /**
     * 获取移交他人详细信息
     */
    @PreAuthorize("@ss.hasPermi('obtain:transfer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tTransferService.selectTTransferById(id));
    }

    /**
     * 新增移交他人
     */
    @PreAuthorize("@ss.hasPermi('obtain:transfer:add')")
    @Log(title = "移交他人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferDto tTransferDto)
    {
        return toAjax(tTransferService.insertTTransfer(tTransferDto));
    }

    /**
     * 修改移交他人
     */
    @PreAuthorize("@ss.hasPermi('obtain:transfer:edit')")
    @Log(title = "移交他人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTransfer tTransfer)
    {
        return toAjax(tTransferService.updateTTransfer(tTransfer));
    }

    /**
     * 删除移交他人
     */
    @PreAuthorize("@ss.hasPermi('obtain:transfer:remove')")
    @Log(title = "移交他人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTransferService.deleteTTransferByIds(ids));
    }
}
